﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XSerialization2
{
    public class Node
    {
        public string V;
        public List<Node> nodes;
    }

    public class Processor : IProcessor
    {
        int tabs = 0;
        public Processor(int tabs)
        {
            this.tabs = tabs;
        }
        public void ProcessBefore(object item)
        {
            Console.WriteLine(new string('\t', tabs) + ((Node)item).V);
        }
        public void ProcessAfter(object item)
        {
        }

        public IEnumerable<object> GetChildren(object item)
        {
            return ((Node)item).nodes ?? Enumerable.Empty<object>();
        }
        public void BackReference(object from, object to)
        {
            var fromn = (Node)from;
            var ton = (Node)to;
            Console.WriteLine(new string('\t', tabs) + "{0} -> {1}", fromn.V, ton.V);
        }
        public IProcessor GetProcessor(object item)
        {
            return new Processor(tabs + 1);
        }
    }
}
